package se.liu.oschi129.game.objects.items;

import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.game.objects.ObjectPlayer;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.objects.WorldMovableObject;

/**
 * This is a regular coin.
 * 
 * @author oschi129
 */
public class ObjectCoin extends WorldMovableObject implements CollectibleObject {
	
	private int timer;
	
	private boolean still;
	
	public ObjectCoin(double x, double y) {
		super(Type.SOFT,AnimationSpace.get("img_coin01"),true,x,y,16,16);
		setVerticalSpeed(-8);
		timer = 0;
		still = false;
		setImageSpeed(0.5);
		setDepth(1);
	}
	
	public ObjectCoin(boolean still, double x, double y) {
		this(x,y);
		if (still) { 
			this.still = true;
			setVerticalSpeed(0);
		}
	}
	
	@Override public void performPickupAction(World world, ObjectPlayer player) {
		world.removeObjectSynchronized(this);
	}
	
	@Override public void performDestructionAction(World world) {
		world.setPoints(world.getPoints() + 25);
		world.setCoins(world.getCoins() + 1);
	}
	
	@Override public void performStepAction(World world) {
		super.performStepAction(world);
		if (!still) {
			if (timer == 4) 
				world.removeObjectSynchronized(this);
			timer++;
		}
	}
	

}
